package cn.hd01.repository;

import java.math.BigDecimal;

import javax.transaction.Transactional;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import cn.hd01.repository.entity.DistributorLevel;

@Repository
public interface DistributorLevelRepository extends JpaRepository<DistributorLevel, Integer> {
	
	Page<DistributorLevel> findAll(Specification<DistributorLevel> spec, Pageable pageable);
	
	Page<DistributorLevel> findAll(Specification<DistributorLevel> spec);
	
	@Modifying
	@Transactional
	@Query(value = "update DistributorLevel set level_name =?1, rebate_rate =?2, update_time = now() where id=?3")
	int updateDistributorLevel(String name, BigDecimal rebateRate, Integer id);
	
}
